package com.fit.entities;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.apache.tapestry5.beaneditor.NonVisual;
import org.apache.tapestry5.beaneditor.Validate;

import com.fit.model.user.Type;

@Table(name = "users")
@Entity
public class User {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@NonVisual
	@Column(name = "id")
	private Long id;
	@Validate("required")
	@Column(name = "user_username", nullable = false)
	private String username;
	@Validate("required")
	@Column(name = "user_password", nullable = false)
	private String password;
	@Validate("required")
	@Column(name = "user_type", nullable = false)
	private String type;
	@Validate("required")
	@OneToOne(optional = true)
	@JoinColumn(name = "user_employee", nullable = true)
	private Employee employee;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public boolean isAdmin() {
		if (type.equalsIgnoreCase(Type.admin.toString())) {
			return true;
		}
		return false;
	}

	public boolean isUser() {
		if (type.equalsIgnoreCase(Type.user.toString())) {
			return true;
		}
		return false;
	}

}
